<template>
	<view class="content">
		<u-navbar :title="navigationBarTitle" :placeholder="true">
			<text slot="left"></text>
		</u-navbar>
		<Shopowner v-if="userInfo.roleCategoryId===3 || userInfo.roleCategoryId===5" :report-data.sync="shopownerData" @getReportData="getReportData" @toStore="toStore"></Shopowner>
		<Shareholder v-else-if="userInfo.roleCategoryId===2" :user-info="userInfo" :shareholderData.sync="shareholderData" @toStore="toStore"></Shareholder>
		<Staff 
			v-else-if="userInfo.roleCategoryId===4" 
			:user-info="userInfo"  
			:reservations.sync="reservations" 
			:staffData.sync="staffData" 
			@toStore="toStore">
		</Staff>
	</view>
</template>

<script>
	import { mapState } from 'vuex'
	import myDate from '@/common/date.js'
	import Staff from "./staff.vue"
	import Shareholder from "./shareholder.vue"
	import Shopowner from "./shopowner.vue"
	export default {
		components: {
			Staff,
			Shareholder,
			Shopowner,
		},
		data() {
			return {
				navigationBarTitle:'',
				shopownerData:{},
				reservations:[],
				staffData:{},
				shareholderData:{},
			}
		},
		onLoad() {
			this.navigationBarTitle = this.store.storeName
		},
		onShow(){
			this.initdata()
		},
		computed: {
			...mapState(['userInfo', 'store'])
		},
		onPullDownRefresh(){
			this.initdata()
			uni.stopPullDownRefresh();//停止刷新
		},
		methods: {
			initdata(){
				if(this.userInfo.roleCategoryId===3 || this.userInfo.roleCategoryId === 5){
					this.getStoreOperatingSummary(`${myDate.getToday()}到${myDate.getToday()}`)
				}else if(this.userInfo.roleCategoryId===4){
					this.getStaffData()
					this.getReservations()
				}else if(this.userInfo.roleCategoryId===2){
					this.getShareholderData()
				}
			},
			toStore(){
				uni.navigateToMiniProgram({
				  appId: 'wx690ba15184c61bd9',
				  path: `/pages/index/reservation/reservation`
				})
			},
			getShareholderData(){
				this.$reqJsonPost('GetStockHolderDetails',{id: this.userInfo.userId}).then(res=>{
					this.shareholderData = res.data
				})
			},
			getReportData(val){
				this.getStoreOperatingSummary(val)
			},
			getStoreOperatingSummary(date){
				this.$reqPost('GetStoreOperatingSummary', {date: date}).then(res=>{
					this.shopownerData = res.data[0]
				})
			},
			getStaffData(){
				this.$reqJsonPost('GetStaffDetails',{id: this.userInfo.userId}).then(res=>{
					this.staffData = res.data;
				})
			},
			getReservations(){
				this.$reqPost('GetAppointmentList', {
					staffId: this.userInfo.userId ,
					status: 0,
					page: 1,
					limit: 40
				}).then(res=>{
					this.reservations = res.data
				})
			}
		}
	}
</script>

<style lang="scss">

</style>